package com.jydd.singlekotlinmvvm.comm.model.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Transaction
import com.jydd.singlekotlinmvvm.comm.model.response.UserInfo

/**
 * created by 韦敏敏
 * on 2020/1/21
 */
@Dao
abstract class UserDao {
    @Transaction
    open fun updateUser(userInfo: UserInfo){
        deleteUser()
        insertUser(userInfo)
    }
     open suspend fun currUser(): UserInfo?{
        return getUsers().firstOrNull()
    }
    @Query("DELETE FROM tb_user")
    abstract fun deleteUser()
    @Insert
    abstract fun insertUser(userInfo: UserInfo)
    @Query("SELECT * FROM tb_user")
    abstract fun getUsers() : List<UserInfo>
}